﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master"Inherits="System.Web.Mvc.ViewPage<Pulog.Models.Post>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

    <%= Html.ValidationSummary("Create was unsuccessful. Please correct the errors and try again.") %>

    <% using (Html.BeginForm()) {%>

    <table class="tableAdd" cellpadding="4" cellspacing="1" align="center">
        <tbody>
            <tr class="hiddenitem">
                <td><label for="title">标题:</label></td>
                <td>
                    <%= Html.TextBox("title") %>
                    <%= Html.ValidationMessage("title", "*") %>
                </td>
            </tr>
            <tr class="visibleitem">
                <td><label for="pubTime">发布时间:</label></td>
                <td>
                    <%= Html.TextBox("pubTime",System.DateTime.Now.ToString()) %>
                    <%= Html.ValidationMessage("pubTime", "*") %>
                </td>
            </tr>
            <tr class="visibleitem">
                <td><label for="property">属性:</label></td>
                <td>
                    <%= Html.DropDownList("property", Helper.GetPropertyListIem())%>
                    <%--<%= Html.TextBox("property", Model.Post.property) %>--%>
                    <%= Html.ValidationMessage("property", "*") %>
                </td>
            </tr>
            <tr class="visibleitem">
                <td><label for="sticky">置顶:</label></td>
                <td>
                    <%= Html.DropDownList("sticky",Helper.GetYesNoSelectedListItem())%>
                    <%= Html.ValidationMessage("sticky", "*") %>
                </td>
            </tr
            <tr class="hiddenitem">
                <td><label for="categoryID">分类:</label></td>
                <td>
                    <%=Html.DropDownList("categoryID",Helper.GetCategoryListItem())%>
                    <%= Html.ValidationMessage("categoryID", "*") %>
                </td>
            </tr>
            <tr class="visibleitem">
                <td><label for="password">查看密码:</label></td>
                <td>
                    <%= Html.TextBox("password") %>
                    <%= Html.ValidationMessage("password", "*") %>
                </td>
            </tr>
            <tr class="visibleitem">
                <td><label for="slug">Slug:</label></td>
                <td>
                    <%= Html.TextBox("slug") %>
                    <%= Html.ValidationMessage("slug", "*") %>
                </td>
            </tr>
            <tr class="visibleitem">
                <td>上传文件</td>
                <td>
                    <div>
                        <div style="margin-top: 5px">
                            Upload file: <span id="fileUploadDiv">
                                <input type="file" id="fileToUpload" name="fileToUpload" size="50" />
                            </span>
                            <input type="button" id="uploadButton" onclick="uploadFile();" value="Upload" />
                            <span id="uploadMessage" style="border: 1px solid #cccccc; color: Red; display: none">
                            </span>
                            <div id="progressBar" style="display: none; position:absolute; color: #660066; font-family: Arial;">
                                <img src="../../Content/images/loading.gif" alt="uploading..." /> File is uploading...
                            </div>
                        </div>
                    </div>
                </td>
            </tr>
            <tr class="hiddenitem">
                <td><label for="content">内容:</label></td>
                <td>
                    <%= Html.TextArea("content", new { style = "width:800px;height:600px;" })%>
                    <%= Html.ValidationMessage("content", "*") %>
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td><input type="submit" value="添加日志" /></td>
            </tr>
        </tbody>
    </table>
     <% } %>
     <div style="display: none;">
                        <iframe name="uploadResponse"></iframe>
                        <% using (Html.BeginForm("Upload", "Posts", FormMethod.Post, new {id = "uploadForm", target = "uploadResponse", enctype = "multipart/form-data" }))
                           {
                        %>
                        <input type="file" id="file1" name="fileToUpload" size="50" value="" />
                        <%
                            }
                        %>
                    </div>
     <div>
        <%=Html.ActionLink("Back to List", "Index") %>
     </div>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript" src="../../Content/tiny_mce/tiny_mce.js"></script>
    <script type="text/javascript">
        tinyMCE.init({
            mode: "textareas",
            theme: "advanced",
            theme_advanced_toolbar_location: "top",
            theme_advanced_toolbar_align: "left",
            theme_advanced_statusbar_location: "bottom",
            theme_advanced_resizing: true,
            relative_urls: false,
            plugins: "syntaxhl,advimage",
            extended_valid_elements: "iframe[src|width|height|name|align]",
            // Theme options
            theme_advanced_buttons1: "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
            theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code," +
                                        "|,insertdate,inserttime,preview,|,forecolor,backcolor,syntaxhl"
        });

        function uploadFile() {
            document.getElementById("uploadMessage").style.display = "none";
            var file = document.getElementById("fileToUpload");
            var uploadFormElement = document.getElementById("uploadForm");

            // display progress bar
            document.getElementById("progressBar").style.display = "block";

            // copy elements
            uploadFormElement.removeChild(uploadFormElement.fileToUpload);
            uploadFormElement.appendChild(file);
            document.getElementById("fileUploadDiv").innerHTML = '<input type="file" id="fileToUpload" name="fileToUpload" size="50" />';

            // submit
            uploadFormElement.submit();
        }

        function uploadFileResponse(response) {
            document.getElementById("progressBar").style.display = "none";
            var errLabel = document.getElementById("uploadMessage");
            errLabel.innerHTML = "";
            eval("var k=" + response);
            if (k.status > 0) {
                errLabel.style.display = "block";
                errLabel.innerHTML = k.message;
            } else
                tinyMCE.execCommand("mceInsertContent", false, k.message);
        }
    </script>
    <script type="text/javascript">
        // auto fill slug field
        $(document).ready(function() {
            $('#title').change(function() {
                str = $('#title').attr("value");
                $('#slug').attr("value", str);
            })
            .change();
        })
    </script>

</asp:Content>

